﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;


public partial class Admin_DevMan_Details : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //详细信息
        //string attid = "";
        //attid = Request.QueryString["num"].ToString();
        string userid = Request.QueryString["id"];
        Session["Admin_Detail_ProID"] = Request.QueryString["id"];
        string pronum = "";
        string proname = "";
        string danwei = "";
        string place = "";
        string auditor = "";
        string condition = "";
        string category = "";
        string buydate = "";
        string ordernot = "";
        string manuname = "";
        string manuinfo = "";
        string worth = "";
        string operation = "";
        string function = "";
        string remarks = "";
        SqlConnection connmsg = new SqlConnection();
        connmsg.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            connmsg.Open();

            //删除记录
            //SqlCommand cmddel = new SqlCommand();
            //string SQLdel = "update Attribute set flag=0 where (att_id=@att_id)";
            //cmddel.Connection = connmsg;
            //cmddel.CommandText = SQLdel;
            //cmddel.CommandType = CommandType.Text;
            ////提交参数 SQL 语句中必须要有@参数
            //SqlParameter ppro_num = new SqlParameter("@att_id", SqlDbType.NVarChar, 10);
            //ppro_num.Value = attid;
            //cmddel.Parameters.Add(ppro_num);
            //cmddel.ExecuteNonQuery();

            SqlCommand cmdmeg = new SqlCommand();
            string SQL = "select pro_num,pro_name,pro_danwei,pro_location,auditor,condition,pro_category,buydate,ordernot,pro_manuname,pro_manuinfo,pro_worth,operation_manual,pro_function,remarks from Products where (pro_num=@pro_num and flag=1)";
            cmdmeg.Connection = connmsg;
            cmdmeg.CommandText = SQL;
            cmdmeg.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter pusername = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            pusername.Value = userid;
            cmdmeg.Parameters.Add(pusername);
            //如果还有其他参数，一并添加
            SqlDataReader reader = cmdmeg.ExecuteReader();
            //使用 SqlDataReader循环读取数据

            while (reader.Read())      //如果可以读（有数据），就开始读
            {
                pronum = reader["pro_num"].ToString();
                proname = reader["pro_name"].ToString();
                danwei = reader["pro_danwei"].ToString();
                place = reader["pro_location"].ToString();
                auditor = reader["auditor"].ToString();
                condition = reader["condition"].ToString();
                category = reader["pro_category"].ToString();
                buydate = reader["buydate"].ToString();
                ordernot = reader["ordernot"].ToString();
                manuname = reader["pro_manuname"].ToString();
                manuinfo = reader["pro_manuinfo"].ToString();
                worth = reader["pro_worth"].ToString();
                operation = reader["operation_manual"].ToString();
                function = reader["pro_function"].ToString();
                remarks = reader["remarks"].ToString();
            }
            Label111.Text = pronum;
            Label112.Text = proname;
            Label113.Text = danwei;
            Label114.Text = place;
            Label115.Text = auditor;
            Label116.Text = condition;

            Label211.Text = category;
            Label212.Text = buydate;
            Label213.Text = ordernot;
            Label214.Text = manuname;
            HyperLink1.NavigateUrl = "Operation/" + operation;
            Label216.Text = worth;

            HyperLink2.Text = manuinfo;
            HyperLink2.NavigateUrl = manuinfo;
            Label312.Text = function;
            Label313.Text = remarks;
        }
        finally
        {
            connmsg.Close();
        }

        //预约表生成
        string id = Request.QueryString["id"].ToString();
        //当前时间及本周一时间获取
        DateTime dt = DateTime.Now;               //当前日期
        string DateNow = dt.ToString("yyyy-MM-dd");
        DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")));  //本周周一
        string DateStartWeek = startWeek.ToString("yyyy-MM-dd");

        //给本周的星期一到五赋值
        string Monday = "";
        string Tuesday = "";
        string Wednesday = "";
        string Thursday = "";
        string Friday = "";
        string Saturday = "";
        string Sunday = "";
        for (int i = 0; i < 7; i++)
        {
            DateTime newdt = startWeek.AddDays(i);
            switch (i)
            {
                case 0: Monday = newdt.ToString("yyyy-MM-dd"); break;
                case 1: Tuesday = newdt.ToString("yyyy-MM-dd"); break;
                case 2: Wednesday = newdt.ToString("yyyy-MM-dd"); break;
                case 3: Thursday = newdt.ToString("yyyy-MM-dd"); break;
                case 4: Friday = newdt.ToString("yyyy-MM-dd"); break;
                case 5: Saturday = newdt.ToString("yyyy-MM-dd"); break;
                case 6: Sunday = newdt.ToString("yyyy-MM-dd"); break;


                default:
                    break;
            }
        }

        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        string path = "";
        string attribute = "";
        string TableContent = "";
        try
        {
            conn.Open();
            string SQLimg = "select pro_img from Products where pro_num=@pronum";
            SqlCommand cmdimg = new SqlCommand();
            cmdimg.Connection = conn;
            cmdimg.CommandType = CommandType.Text;
            cmdimg.CommandText = SQLimg;
            SqlParameter p1 = new SqlParameter("@pronum", id);
            cmdimg.Parameters.Add(p1);
            //cmdimg.ExecuteNonQuery();
            path = cmdimg.ExecuteScalar().ToString();

            ////添加的属性
            //string SQLatt = "select keyword,pro_value from Attribute where att_num=@pronum";
            //SqlCommand cmdatt = new SqlCommand();
            //cmdatt.Connection = conn;
            //cmdatt.CommandType = CommandType.Text;
            //cmdatt.CommandText = SQLatt;
            //SqlParameter p2 = new SqlParameter("@pronum", id);
            //cmdatt.Parameters.Add(p2);
            //using (SqlDataReader reader = cmdatt.ExecuteReader())
            //{
            //    while (reader.Read())
            //    {   //  reader [0]  为序数列的值，  “XH” 学号字段的值
            //        attribute += reader["keyword"] + ":&nbsp;";
            //        attribute += reader["pro_value"] + "<br />";
            //    }
            //}

            //预约表的添加

            string SqlGetCondition = "select condition from products where pro_num=@pro_num and flag=1";
            SqlCommand SqlCmdGetCondition = new SqlCommand();
            SqlCmdGetCondition.Connection = conn;
            SqlCmdGetCondition.CommandType = CommandType.Text;
            SqlCmdGetCondition.CommandText = SqlGetCondition;
            SqlParameter pGetCondition = new SqlParameter("@pro_num", id);
            SqlCmdGetCondition.Parameters.Add(pGetCondition);
            using (SqlDataReader reader = SqlCmdGetCondition.ExecuteReader())
            {
                while (reader.Read())
                {
                    condition = reader["condition"].ToString();
                }
            }
            if (condition != "正常")
            {
                Label11.Text = "暂停预约";
                Label21.Text = "暂停预约";
                Label31.Text = "暂停预约";
                Label41.Text = "暂停预约";
                Label51.Text = "暂停预约";
                Label61.Text = "暂停预约";
                Label71.Text = "暂停预约";

                Label12.Text = "暂停预约";
                Label22.Text = "暂停预约";
                Label32.Text = "暂停预约";
                Label42.Text = "暂停预约";
                Label52.Text = "暂停预约";
                Label62.Text = "暂停预约";
                Label72.Text = "暂停预约";

                Label13.Text = "暂停预约";
                Label23.Text = "暂停预约";
                Label33.Text = "暂停预约";
                Label43.Text = "暂停预约";
                Label53.Text = "暂停预约";
                Label63.Text = "暂停预约";
                Label73.Text = "暂停预约";

                Label14.Text = "暂停预约";
                Label24.Text = "暂停预约";
                Label34.Text = "暂停预约";
                Label44.Text = "暂停预约";
                Label54.Text = "暂停预约";
                Label64.Text = "暂停预约";
                Label74.Text = "暂停预约";

                Label15.Text = "暂停预约";
                Label25.Text = "暂停预约";
                Label35.Text = "暂停预约";
                Label45.Text = "暂停预约";
                Label55.Text = "暂停预约";
                Label65.Text = "暂停预约";
                Label75.Text = "暂停预约";
            }
            else
            {
                string sqltable = "select date,time from booking where (pro_num=@pro_num and flag=1 and condition=N'预约成功')";
                SqlCommand cmdtable = new SqlCommand();
                cmdtable.Connection = conn;
                cmdtable.CommandType = CommandType.Text;
                cmdtable.CommandText = sqltable;
                SqlParameter ptable = new SqlParameter("@pro_num", id);
                cmdtable.Parameters.Add(ptable);
                using (SqlDataReader reader = cmdtable.ExecuteReader())
                {
                    //TableContent = "<table>< tr >< td ></ td >< td > 星期一 </ td >< td > 星期二 </ td >< td > 星期三 </ td >< td > 星期四 </ td >< td > 星期五 </ td >< td > 星期六 </ td >< td > 星期日 </ td ></ tr > ";
                    while (reader.Read())
                    {   //  reader [0]  为序数列的值，  “XH” 学号字段的值
                        string FlagTime = reader["time"].ToString();
                        string GetDate = reader["date"].ToString();
                        switch (FlagTime)
                        {
                            case "08:00-10:00":
                                if (GetDate == Monday)
                                {
                                    Label11.Text = "已预约";
                                    Label11.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Tuesday)
                                {
                                    Label21.Text = "已预约";
                                    Label21.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Wednesday)
                                {
                                    Label31.Text = "已预约";
                                    Label31.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Thursday)
                                {
                                    Label41.Text = "已预约";
                                    Label41.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Friday)
                                {
                                    Label51.Text = "已预约";
                                    Label51.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Saturday)
                                {
                                    Label61.Text = "已预约";
                                    Label61.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Sunday)
                                {
                                    Label71.Text = "已预约";
                                    Label71.ForeColor = System.Drawing.Color.Red;
                                }
                                break;
                            case "10:00-12:00":
                                if (GetDate == Monday)
                                {
                                    Label12.Text = "已预约";
                                    Label12.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Tuesday)
                                {
                                    Label22.Text = "已预约";
                                    Label22.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Wednesday)
                                {
                                    Label32.Text = "已预约";
                                    Label32.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Thursday)
                                {
                                    Label42.Text = "已预约";
                                    Label42.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Friday)
                                {
                                    Label52.Text = "已预约";
                                    Label52.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Saturday)
                                {
                                    Label62.Text = "已预约";
                                    Label62.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Sunday)
                                {
                                    Label72.Text = "已预约";
                                    Label72.ForeColor = System.Drawing.Color.Red;
                                }
                                break;
                            case "14:00-16:00":
                                if (GetDate == Monday)
                                {
                                    Label13.Text = "已预约";
                                    Label13.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Tuesday)
                                {
                                    Label23.Text = "已预约";
                                    Label23.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Wednesday)
                                {
                                    Label33.Text = "已预约";
                                    Label33.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Thursday)
                                {
                                    Label43.Text = "已预约";
                                    Label43.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Friday)
                                {
                                    Label53.Text = "已预约";
                                    Label53.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Saturday)
                                {
                                    Label63.Text = "已预约";
                                    Label63.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Sunday)
                                {
                                    Label73.Text = "已预约";
                                    Label73.ForeColor = System.Drawing.Color.Red;
                                }
                                break;
                            case "16:00-18:00":
                                if (GetDate == Monday)
                                {
                                    Label14.Text = "已预约";
                                    Label14.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Tuesday)
                                {
                                    Label24.Text = "已预约";
                                    Label24.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Wednesday)
                                {
                                    Label34.Text = "已预约";
                                    Label34.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Thursday)
                                {
                                    Label44.Text = "已预约";
                                    Label44.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Friday)
                                {
                                    Label54.Text = "已预约";
                                    Label54.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Saturday)
                                {
                                    Label64.Text = "已预约";
                                    Label64.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Sunday)
                                {
                                    Label74.Text = "已预约";
                                    Label74.ForeColor = System.Drawing.Color.Red;
                                }
                                break;
                            case "19:00-21:00":
                                if (GetDate == Monday)
                                {
                                    Label15.Text = "已预约";
                                    Label15.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Tuesday)
                                {
                                    Label25.Text = "已预约";
                                    Label25.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Wednesday)
                                {
                                    Label35.Text = "已预约";
                                    Label35.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Thursday)
                                {
                                    Label45.Text = "已预约";
                                    Label45.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Friday)
                                {
                                    Label55.Text = "已预约";
                                    Label55.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Saturday)
                                {
                                    Label65.Text = "已预约";
                                    Label65.ForeColor = System.Drawing.Color.Red;
                                }
                                if (GetDate == Sunday)
                                {
                                    Label75.Text = "已预约";
                                    Label75.ForeColor = System.Drawing.Color.Red;
                                }
                                break;


                            default:
                                break;
                        }
                        //attribute += reader["keyword"] + ":&nbsp;";
                        //attribute += reader["pro_value"] + "<br />";
                    }
                    //if (reader.Read()==false)
                    //{
                    //    TableContent = "暂还没有预约信息哦！";
                    //}
                }
            }

            
            string tabelall = "<table class='layui-table' style='width: 70%; margin-left:15% '><thead> <tr><td colspan='8' style='background-color: #EEE;font-size:large;text-align:center'>该设备的其他属性</td></tr><tr><th>属性名称</th><th>属性值</th></tr></thead>";
            SqlCommand cmdmsg = new SqlCommand();
            string SQLmsg = "select att_id,keyword,pro_value from Attribute where att_num=@pro_num";
            cmdmsg.Connection = conn;
            cmdmsg.CommandText = SQLmsg;
            cmdmsg.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            ppro_num.Value = id;
            cmdmsg.Parameters.Add(ppro_num);
            int k = 0;
            using (SqlDataReader readermsg = cmdmsg.ExecuteReader())
            {
                int fieldcount = readermsg.FieldCount;      //取字段总数
                if (!readermsg.HasRows)            //有数据  ---行
                {
                    MsgKey.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>此仪器没有被添加过其他属性</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (readermsg.Read())               //当有数据可读时
                    {
                        trd += "<tr>";         //数据行开始，行以tr起
                        for (int i = 1; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + readermsg[i].ToString() + "</td>";
                        }
                        /* trd += "<td><a title='删除'  href = 'Admin_DevMan_Details.aspx?" + readermsg[0].ToString() + "'><i class='layui-icon'>&#xe640;</i></td></tr>";  */           //行结束
                        k = k + 1;
                    }
                    //trd += "<tr><td colspan = '4'><button class='layui-btn layui-btn-danger' onclick='delAll()'><i class='layui-icon'></i>批量删除</button></td></tr>";
                    MsgKey.Text = tabelall + trd + "</tbody></table>";
                }
            }

        }
        finally
        {
            conn.Close();
        }
        Image1.ImageUrl = "Photos/" + path;

        

        Image2.ImageUrl = "qrcode/" + userid + ".png";


        
    }
    //LabAtt.Text = attribute.ToString();


    protected void BtnRevise_Click(object sender, EventArgs e)
    {
        // Session["Admin_Detail_ProID"] = Request.QueryString["id"];

        Response.Redirect("Admin_DevMan_Revise.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_DevMan_Revise.aspx");
    }
}


//}